package com.sss.springboot.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.sss.springboot.model.User;
import com.sss.springboot.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Reference(interfaceClass = UserService.class)
    private UserService userService;

    //@RequestMapping("/index")
    @GetMapping(value = "/index")
    public @ResponseBody
    Object findAll() {
        Map<String, Object> all = userService.findAll();
        return all;
    }

    //@RequestMapping("/updateById")
    @PutMapping(value = "/updateById")
    public @ResponseBody
    User updateById(@RequestBody User user) {
        return userService.update(user);
    }

    @GetMapping(value = "/index/{id}")
    public @ResponseBody
    User select(@PathVariable(name = "id") String id) {
        return userService.select(id);
    }


    @RequestMapping("/user")
    public String user(Model model){
        List<User> user = userService.findUser();
        model.addAttribute("user",user);
        return "user";
    }
}
